$(document).ready(function () {
    $('#menu > ul').superfish({
        pathClass: 'overideThisToUse',
        delay: 0,
        animation: {height: 'show'},
        speed: 'normal',
        autoArrows: false,
        dropShadows: false,
        disableHI: false, /* set to true to disable hoverIntent detection */
        onInit: function () {
        },
        onBeforeShow: function () {
        },
        onShow: function () {
        },
        onHide: function () {
        }
    });

    $('#menu > ul').css('display', 'block');
});

function getURLVar(key) {
    var value = [];

    var query = String(document.location).split('?');

    if (query[1]) {
        var part = query[1].split('&');

        for (i = 0; i < part.length; i++) {
            var data = part[i].split('=');

            if (data[0] && data[1]) {
                value[data[0]] = data[1];
            }
        }

        if (value[key]) {
            return value[key];
        } else {
            return '';
        }
    }
}

$(document).ready(function () {
    route = getURLVar('route');

    if (!route) {
        $('#dashboard').addClass('selected');
    } else {
        part = route.split('/');

        url = part[0];

        if (part[1]) {
            url += '/' + part[1];
        }

        $('a[href*=\'' + url + '\']').parents('li[id]').addClass('selected');
    }

    $('#menu ul li').on('click', function () {
        $(this).addClass('hover');
    });

    $('#menu ul li').on('mouseout', function () {
        $(this).removeClass('hover');
    });
});


function customTourAction(type, tourId, baseUrl) {
    if (type == 'Done') {
        $.ajax({
            url: baseUrl + "/?route=travel/custom/updatecustomtour",
            type: "post",
            data: {
                'status': 'Done',
                'tourId': tourId
            },
            dataType: "json",
            success: function (result) {
                alert('Well Done');
                $('#tr_' + tourId).remove();
            }
        });
    }
    if (type == 'Cancel') {
        var reason = prompt("Please give reason!", "");
        if (reason != null && reason.length > 0) {
            $.ajax({
                url: baseUrl + "/?route=travel/custom/updatecustomtour",
                type: "post",
                data: {
                    'status': 'cancel',
                    'tourId': tourId,
                    'reason': reason
                },
                dataType: "json",
                success: function (result) {
                    alert('Please focus!!!');
                    $('#tr_' + tourId).remove();
                }
            });
        }
    }


}